package com.burpee.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.burpee.ui.Addfile;

@Repository(value="addfileDao")
public class AddfileDaoImpl implements AddfileDao {
	
	SqlSessionTemplate sqlSessionTemplate;

	@Autowired
	public void setSqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
	}

	public List<Addfile> list() {
		
		List<Addfile> list=null;
		
		try {
			list = sqlSessionTemplate.selectList("addfilelist");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return list;
	}

	public Addfile view(Addfile addfile) {
		
		Addfile addfileview=new Addfile();
		
		try {
			addfileview = sqlSessionTemplate.selectOne("addfileview", addfile);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return addfileview;
	}

	public int add(Addfile addfile) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.insert("addfileadd",addfile);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

//	public int modify(Addfile addfile) {
//		int result = 0;
//
//		try {
//			result = (int)sqlSessionTemplate.update("addfilemodify",addfile);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//
//		return result;
//	}

	public int remove(Addfile addfile) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.delete("addfileremove",addfile);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

}
